package com.baicaoyuan.web.repository;

import com.baicaoyuan.web.model.CashOutDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface CashOutRepository extends JpaRepository<CashOutDO, Long> {

    @Transactional
    @Modifying
    @Query(value = "update t_cash_out set status = ?2 , operate_time = sysdate() where id = ?1", nativeQuery = true)
    Integer updateStatus(Long id, String status);

    @Query(value = "select * from t_cash_out where status like ?2 and telephone like ?1 order by create_time desc Limit ?3,?4", nativeQuery = true)
    List<CashOutDO> getCashOuts(String telephone, String status, Integer page, Integer size);


    Integer countAllByStatusLikeAndTelephoneLike(String status, String telephone);

    List<CashOutDO> findByUserFkOrderByCreateTimeDesc(Long userId, Pageable pageable);
}
